package com.ruyuan.rapid.disruptor;

import com.lmax.disruptor.RingBuffer;

import java.nio.ByteBuffer;

public class OrderEventProducer {

    private RingBuffer<OrderEvent> ringBuffer;

    public OrderEventProducer(RingBuffer<OrderEvent> ringBuffer){
        this.ringBuffer = ringBuffer;
    }

    public void putData(long price) {
        long next = this.ringBuffer.next();
        try {
            OrderEvent orderEvent = this.ringBuffer.get(next);
            orderEvent.setPrice(price);
        }finally {
            this.ringBuffer.publish(next);
        }
    }
}
